layui.define(['layer', 'Const'], function(exports) {
  var $ = layui.jquery;
  var layer = layui.layer;
  var Const = layui.Const;

  function ajax(parms) {
    $.ajax({
      url: parms.url,
      method: parms.method,
      data: parms.data,
      success: function(res) {
        if (Const.NOLOGIN_CODE == res.code) {
          window.location.href = '/html/user/login.html';
        } else if (Const.SUCCESS_CODE != res.code) {
          layer.msg(res.msg);
        } else {
          parms.success(res.data);
        }
      }
    });
  };

  exports('ajax', ajax);
});
